package main

import (
	"encoding/json"
	"fmt"
	proto1 "go_final/demos/proto_vs_json/proto"

	"github.com/golang/protobuf/proto"
)

type Hello struct {
	Name    string
	Age     int32
	Courses []string
}

func main() {
	jsonStruct := Hello{
		Name: "Felix",
		Age:  18,
		Courses: []string{
			"golang",
			"typescript",
			"swift",
		},
	}
	mJsonStruct, _ := json.Marshal(jsonStruct)
	fmt.Println("mJsonStruct ===> ", mJsonStruct)
	fmt.Println("string(mJsonStruct) ===> ", string(mJsonStruct))
	fmt.Println("len(mJsonStruct) ===> ", len(mJsonStruct))

	req := proto1.HelloRequest{
		Name: "Felix",
		Age:  18,
		Courses: []string{
			"golang",
			"typescript",
			"swift",
		},
	}
	mReq, _ := proto.Marshal(&req)
	fmt.Println("mReq ===> ", mReq)
	fmt.Println("string(mReq) ===> ", string(mReq))
	fmt.Println("len(mReq) ===> ", len(mReq))

	// Unmarshal proto
	newReq := proto1.HelloRequest{}
	_ = proto.Unmarshal(mReq, &newReq)
	fmt.Println("newReq ===> ", newReq.Name, newReq.Age, newReq.Courses)
}
